﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cocos2d;
using CocosDenshion;

namespace Meteorite
{
    public class PauseLayer : CCLayer
    {
        CCMenuItemLabel BtnResume;
        CCMenuItemLabel BtnExit;

        public PauseLayer()
        {
            //base.init();
        }

        public override void onEnter()
        {
            base.onEnter();

	        CCSize size = CCDirector.sharedDirector().getWinSize();

            CCLayerColor layer = CCLayerColor.layerWithColorWidthHeight(new ccColor4B(0, 0, 0, 180), size.width, size.height);
            this.addChild(layer);

            CCLabelBMFont pLabel = CCLabelBMFont.labelWithString(GameConstant.PauseScene_Btn_Pause, GameConstant.Font_Futura_48);
            pLabel.position = new CCPoint(size.width / 2, size.height-50);
            pLabel.scale = 2.0f;
            this.addChild(pLabel);

            CCLabelBMFont Resume = CCLabelBMFont.labelWithString(GameConstant.PauseScene_Btn_Resume, GameConstant.Font_Futura_48);
            BtnResume = CCMenuItemLabel.itemWithLabel(Resume, this, this.callback);

            CCLabelBMFont Exit = CCLabelBMFont.labelWithString(GameConstant.PauseScene_Btn_Exit, GameConstant.Font_Futura_48);
            BtnExit = CCMenuItemLabel.itemWithLabel(Exit, this, this.callback);

            CCMenu pMenu = CCMenu.menuWithItems(BtnResume, BtnExit);
            pMenu.alignItemsVertically();
            addChild(pMenu);

        }

        public void callback(CCObject pSender)
        {
            if (pSender == BtnResume)
            {
                Meteorite.Pause = false;
                parent.removeChild(this, false);
            }
            else if (pSender == BtnExit)
            {
                parent.removeChild(this, false);
                CCScene pScene = new MainMenuScene();
                CCDirector.sharedDirector().replaceScene(pScene);
                Meteorite.Pause = false;
            }
            if (0 == UserData.Instance().GetValue(GameConstant.UserData_Sound))
            {
                SimpleAudioEngine.sharedEngine().playEffect(CCFileUtils.fullPathFromRelativePath(GameConstant.Sound_Btn));
            }
        }
    }
}
